<?php

namespace Modules\Shop\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Routing\Controller;
use Illuminate\View\FileViewFinder;
use Modules\Shop\Entities\Article;
use Modules\Shop\Entities\Category;
use Modules\Shop\Entities\Comment;
use View;
use App;
class HomeController extends Controller
{

    public function __construct()
    {
        //定义模板文件的路劲
        //获取配置文件中的默认模板名称
        $default = \HDModule::config('admin.config.template');
        $path = [public_path('templates/' . $default)];
        //动态改变当前类找的模板初始地址
        View::setFinder(new FileViewFinder(App::make('files'),$path));
    }

    /**
     *
     * 首页
     *
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function index()
    {
        //dd('我是首页');
        return view('index');
    }

    /**
     * @param $cid
     * 分类列表
     */
    public function lists($cid){
        $category = Category::find($cid);
        return view('list',compact('category'));
    //dd($cid);
    }

    /**
     * 详情
     */
    public function content(Article $article){
//        dd($article);
        //获取当前文章的已审核的评论内容
        $comments = $article->comment->where('status',1);
//        dd($comments);
        //加载文章详情模板
        return view('info',compact('article','comments'));
    }
}
